package com.newlink.building.userinfo.mvp

import androidx.lifecycle.Lifecycle
import androidx.lifecycle.LifecycleOwner
import androidx.lifecycle.OnLifecycleEvent
import com.newlink.building.common_base.base.BasePresenter
import com.newlink.building.common_base.ext.ss
import com.newlink.building.common_base.model.bean.*
import com.newlink.building.userinfo.mvp.contract.Module_UserInfo_AuthCardAddContract
import com.newlink.building.userinfo.mvp.model.Module_UserInfo_AuthCardAddModel

/**
 * @author wangyang
 * @date 2022/9/20
 * @description 我的-关于页面的Presenter
 */
class Module_UserInfo_AuthCardAddPresenter : BasePresenter<Module_UserInfo_AuthCardAddContract.Model, Module_UserInfo_AuthCardAddContract.View>(),
    Module_UserInfo_AuthCardAddContract.Presenter {

    private var isResume = false

    override fun createModel(): Module_UserInfo_AuthCardAddContract.Model? = Module_UserInfo_AuthCardAddModel()

//    override fun onAuthConfirmResponse(
//        id: Int,
//        result: BaseBean?
//    ) {
//        if (result?.code == 200) {
//            if (result?.responseType == KcpRquestType.TYPE_APPKEY_ADD) {
//                mView?.onAddCardDataSuccess()
//            } else if (result?.responseType == KcpRquestType.TYPE_APPKEY_DELETE) {
//                mView?.onDeleteCardDataSuccess()
//            }
//        } else {
//            if (result?.responseType == KcpRquestType.TYPE_APPKEY_ADD) {
//                mView?.onAddCardDataFailed()
//            } else if (result?.responseType == KcpRquestType.TYPE_APPKEY_DELETE) {
//                mView?.onDeleteCardDataFailed()
//            }
//        }
//    }
//
//    override fun onAuthListResponse(
//        id: Int, result: KcpResult<FaceListData>?
//    ) {
//        Log.d("jake", "card total >>> ${result?.data?.total}")
//        Log.d("jake", "card list  >>> ${result?.data?.list}")
//        val total = result?.data?.total
//        val list = result?.data?.list
//        mView?.getCardListSuccess(total!! , list)
//    }


    @OnLifecycleEvent(Lifecycle.Event.ON_RESUME)
    open fun onResume(owner: LifecycleOwner) {
        isResume = true
    }

    @OnLifecycleEvent(Lifecycle.Event.ON_PAUSE)
    open fun onPause(owner: LifecycleOwner) {
        isResume = false
    }

    override fun getCardList(token: String, uId: String) {
        val data = LoadAuthDataRequestBody(keyType = 1)
        mModel?.getCardList(LoadFaceListDataRequest(accessToken = token, uId = uId, data = data))
            ?.ss(mModel, mView) {
                if (it?.data != null) {
                    mView?.getCardListSuccess(it.data.total, it.data.list)
                } else {
                    mView?.getCardListFailed()
                }
            }
    }

    override fun removeCard(accessToken: String, s: String, item: AuthResponseBody) {
        val keyId = item.id
        val body = DeleteFaceDataRequestBody(mutableListOf("$keyId"))
        mModel?.removeCard(DeleteFaceDataRequest(accessToken = accessToken, uId = s, data = body))
            ?.ss(mModel, mView) {
                if (it?.code == 200) {
                    mView?.onDeleteCardDataSuccess()
                } else {
                    mView?.onDeleteCardDataFailed()
                }
            }
    }

}